package com.runvp.rest.user;

import com.runvp.common.annotation.Log;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.enums.BusinessType;
import com.runvp.common.model.vo.auth.PhoneVO;
import com.runvp.common.util.auth.SecurityUtils;
import com.runvp.service.auth.service.WechatAuthService;
import com.runvp.service.biz.domain.BizCustomer;
import com.runvp.service.biz.service.IBizCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 消费者Controller
 *
 * @author runvp
 * @date 2022-09-15
 */
@Controller
@RequestMapping("/app/customer")
public class BizCustomerController extends BaseController {

    @Autowired
    private WechatAuthService authService;

    @Autowired
    private IBizCustomerService bizCustomerService;

    /**
     * 发送验证码
     */
    @Log(title = "用户信息", businessType = BusinessType.OTHER)
    @ResponseBody
    @GetMapping("/info")
    public AjaxResult info() {
        return AjaxResult.success(bizCustomerService.selectBizCustomerById(SecurityUtils.getUserId()));
    }

    /**
     * 获取消费者手机号
     */
    @Log(title = "获取消费者手机号", businessType = BusinessType.OTHER)
    @PostMapping("/getPhone")
    @ResponseBody
    public AjaxResult getPhone(@RequestBody PhoneVO phoneVO) {
        return AjaxResult.success(authService.getPhone(phoneVO));
    }

    /**
     * 更新消费者信息
     */
    @Log(title = "更新消费者信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody BizCustomer bizCustomer) {
        bizCustomer.setId(SecurityUtils.getUserId());
        bizCustomer.setUpdateBy(String.valueOf(bizCustomer.getId()));
        return toAjax(bizCustomerService.updateBizCustomer(bizCustomer));
    }
}
